package com.mail.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.PmsSkuStockMapper;
import com.mail.model.db.PmsSkuStock;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.WeakHashMap;

@DubboService
public class PmsSkuStockApiImpl implements PmsSkuStockApi {

    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;

    @Override
    public void updateSkuStock(Long pid, PmsSkuStock pmsSkuStock) {
        LambdaQueryWrapper<PmsSkuStock> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PmsSkuStock::getProductId, pid)
                .eq(PmsSkuStock::getId, pmsSkuStock.getId());
        pmsSkuStockMapper.update(pmsSkuStock, wrapper);
    }

    //根据商品ID及sku编码模糊搜索sku库存
    @Override
    public List<PmsSkuStock> findBypid(Integer pid, String keyword) {
        LambdaQueryWrapper<PmsSkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsSkuStock::getProductId, pid);
        queryWrapper.like(keyword != null, PmsSkuStock::getSkuCode, keyword);
        return pmsSkuStockMapper.selectList(queryWrapper);
    }
}
